<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // 函数控制何时实例化Promise
        // function runp1() {
        //     const p1 = new Promise(r => console.log('立即打印'));
        //     return p1;
        // }
        // runp1().then(() => {
        //     console.log('p1.then执行')
        // })
        // 异步-async   同步-sync
        function runAsync(x) {
            const p = new Promise(resolve => setTimeout(() => resolve(x, console.log(x)), 1000 * x));
            return p;
        }
        // runAsync('ppp')
        //     .then(data => {
        //         console.log(data, 'then')
        //     })
        // js 单线程 同步任务
        // Promise.all() 并发 保持Promise顺序返回结果
        Promise.all([runAsync(1), runAsync(3), runAsync(2)])// 1 等1秒后 2 等1秒后 3 [1, 3, 2]
            // thenable 等到all所有的执行后，才执行
            .then(res => console.log(res))
    </script>
</body>

</html>